package br.com.caelum.vraptor.controller;

import java.util.List;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.auth_annotations.Administrador;
import br.com.caelum.vraptor.auth_annotations.Restrito;
import br.com.caelum.vraptor.dao.GenericDAO;
import br.com.caelum.vraptor.dao.ReservaDAO;
import br.com.caelum.vraptor.entidades.Reserva;

@Controller
public class ReservaController {
	

	@Inject
    private Result result;
    
    @Inject
    private GenericDAO<Reserva> dao;
    @Inject
    private ReservaDAO reservaDAO;
    
    public void add(){
            
    }
    
    public List<Reserva> list(){
            return dao.find();
    }
    
    public void save(Reserva reserva){
    	reserva = reservaDAO.find(reserva);
    	if(reserva!=null){
    		result.redirectTo(ReservaController.class).error();
    	}else{
    		 dao.save(reserva);
             result.redirectTo(ReservaController.class).list();
    	}
    }
    
    public Reserva edit(int id){
        return dao.find(id);
    }
    
    public void delete(int id){
    	Reserva reserva= new Reserva();
        reserva.setId(id);
        dao.delete(reserva);
        result.redirectTo(this).list();
    }
    
    public void error(){
    	
    }


}
